package com.java.actual.snake;

public class SnakeRunnable implements Runnable {

	private Snake snake;

	private StagePanel stagePanel;

	public SnakeRunnable(Snake snake, StagePanel stagePanel) {
		this.snake = snake;
		this.stagePanel = stagePanel;
	}

	public void run() {
		while (true) {
			if (!snake.move()){
				break;
			}
			// 重绘
			stagePanel.repaint();
			try {
				Thread.sleep(snake.getSpeed());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
